package com.znf4.controller.common;
/*package com.znf4.platform.controller.common;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import com.znf4.platform.common.core.config.SystemConfig;
import com.znf4.platform.common.core.utils.FtpUtil;
import com.znf4.platform.common.core.utils.SFTPUtil;
import com.znf4.platform.common.core.utils.StringUtil;

*//**
 * @类功能说明： 上传文件公共类.
 *//*
@Controller
@RequestMapping("/fileUpload")
public class FileUploadController {

    private static final Log LOG = LogFactory.getLog(FileUploadController.class);

    *//**
     * 函数功能说明：文件批量上传.
     * @param model 图片所属模块:adv、goods、notice、product、shop、merchant
     * @param type 图片分类：logo、atlas 图集、carousel 轮播图
     * @param flag 图片类型：swf、img、media、zip
     * @param response
     * @param files
     * @throws IOException
     * @return void
     * @throws
     *//*
    @RequestMapping(value = "/fileUpload")
    @ResponseBody
    public void fileUpload(MultipartRequest files, @RequestParam("model") String model, 
            @RequestParam("type") String type, @RequestParam("flag") String flag, 
            HttpServletResponse response) throws IOException {
        String destPath = "";
        // 我试了一下虽然每个文件是分别上传的 但此处还要用Map来获取
        Map<String, MultipartFile> fileMap = files.getFileMap();
        for (String key : fileMap.keySet()) {
            MultipartFile file = fileMap.get(key);
            try {
                if (!file.isEmpty()) {
                    // 上传文件到FTP服务器
                    String fileName = StringUtil.get32UUID() + "." + StringUtil.getExt(file.getOriginalFilename());;
//                    destPath = FtpUtil.upload(SystemConfig.FTP_PROJECT, file.getInputStream(), fileName, model, flag);
                    destPath = SFTPUtil.upload(SystemConfig.FTP_PROJECT, file.getInputStream(), fileName, model, flag);
                } else {
                	destPath = "上传文件不能为空";
                }
            } catch (Exception e) {
                LOG.error(e);
            }
        }
        printInfo(response, destPath);
    }

    *//**
     * 函数功能说明 ： 上传编辑器图片到FTP.
     * @param model 图片所属模块:adv、goods、notice、product、shop、merchant
     * @param type 图片分类：logo、atlas、carousel
     * @param flag 图片类型：swf、img、media、zip
     * @param response
     * @param file
     * @throws IOException
     * @return：void   
     * @throws
     *//*
    @RequestMapping(value = "/xheditorUpload", method = RequestMethod.POST)
    @ResponseBody
    public void fileUpload(@RequestParam("filedata") MultipartFile file, @RequestParam("model") String model, 
            @RequestParam("type") String type, @RequestParam("flag") String flag, 
            HttpServletResponse response) throws IOException {
        String result = "";
        try {
            if (!file.isEmpty()) {
                // 上传文件到FTP服务器
            	// 上传文件到FTP服务器
                String fileName = StringUtil.get32UUID() + "." + StringUtil.getExt(file.getOriginalFilename());;
//                String destPath = FtpUtil.upload(SystemConfig.FTP_PROJECT, file.getInputStream(), fileName, model, flag);
                String destPath = SFTPUtil.upload(SystemConfig.FTP_PROJECT, file.getInputStream(), fileName, model, flag);
                result =  "{\"err\":\"\",\"msg\":\"" + destPath + "\"}";
            } else {
                result = "{\"error\":\"" + "上传文件不能为空" + "\",\"msg\":\"\"}";
            }
        } catch (Exception e) {
            LOG.error(e);
        }
        printInfo(response, result);
    }

    *//**
     * 使用I/O流输出 json格式的数据
     * 
     * @param response
     * @param result
     * @throws IOException
     *//*
    public void printInfo(HttpServletResponse response, String result)
            throws IOException {
        response.setContentType("text/html; charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter out = response.getWriter();
        out.println(result);
        out.flush();
        out.close();
    }

}
*/